package com.zzx.day57Demo.DAO.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.FetchMode;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.context.annotation.Scope;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.zzx.day57Demo.DAO.DecoratentDAO;
import com.zzx.day57Demo.model.Decoratent;

@Repository("decoratentDAO")
@Scope("prototype")
@SuppressWarnings("deprecation")
public class DecoratentDAOImpl extends HibernateDaoSupport implements DecoratentDAO {

	@SuppressWarnings("unchecked")
	public List<Decoratent> findAll() {
		return (List<Decoratent>) getHibernateTemplate().executeFind(new HibernateCallback<List<Decoratent>>() {

			@Override
			public List<Decoratent> doInHibernate(Session session) throws HibernateException, SQLException {
				// TODO Auto-generated method stub
				return session.createCriteria(Decoratent.class).setFetchMode("exp", FetchMode.JOIN).list();
			}
		});
	}
	public void saveOrUpdate(Decoratent dec){
		getHibernateTemplate().saveOrUpdate(dec);
	}
	public Decoratent findById(int decId){
		return getHibernateTemplate().get(Decoratent.class, decId);
	}

	public void delete(Decoratent dec){
		getHibernateTemplate().delete(dec);
		
	}


}
